#!/bin/sh
#
### BEGIN INIT INFO
# Provides:            lizardfs-cgiserv
# Required-Start:      $local_fs $network $syslog
# Required-Stop:       $local_fs $syslog
# Should-Start:        $syslog
# Should-Stop:         $network $syslog
# Default-Start:       2 3 4 5
# Default-Stop:        0 1 6
# Short-Description:   Start up the lizardfs-cgiserv server daemon
# Description:         LizardFS is a distributed, scalable, fault-tolerant and highly available file system.
#                      This service starts up the LizardFS cgiserv server daemon.
### END INIT INFO

# Source function library.
. @initddir@/functions

# Source networking configuration.
. /etc/sysconfig/network

LZFS_USER=nobody
PID_FILE=/var/run/lizardfs-cgiserv.pid

# Check that networking is up.
[ "${NETWORKING}" == "no" ] && exit 0
[ -x "/usr/sbin/lizardfs-cgiserver" ] || exit 1

RETVAL=0
prog="lizardfs-cgiserver"

start () {
    echo -n $"Starting $prog: "
    daemon --pidfile $PID_FILE $prog -p $PID_FILE -u $LZFS_USER
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
    return $RETVAL
}

stop () {
    echo -n $"Stopping $prog: "
    killproc -p $PID_FILE $prog
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
    return $RETVAL
}

restart () {
    stop
    start
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart|reload)
    restart
    ;;
  condrestart)
    [ -e /var/lock/subsys/$prog ] && restart
    RETVAL=$?
    ;;
  status)
    status $prog
    RETVAL=$?
    ;;
  *)
    echo $"Usage: $0 {start|stop|restart|condrestart|status}"
    RETVAL=1
esac

exit $RETVAL
